package com.fqdf.framework.android.util;

import java.text.DecimalFormat;

public class FormatUtil {


    /**
     * 格式化距离
     *
     * @param meter
     * @return
     */
    public static String formatMeter(String meter) {
        String fileSizeString = "m";
        if (CheckLogicUtil.isEmpty(meter)) {
            return fileSizeString;
        }
        try {

            int meterI = Integer.parseInt(meter);
            DecimalFormat df = new DecimalFormat("#.0");

            if (meterI < 1000) {
                fileSizeString = meterI + "m";
            } else {
                fileSizeString = df.format(meterI / 1000.0) + "km";
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        return fileSizeString;
    }


    /**
     * 格式化距离
     *
     * @param meter
     * @return
     */
    public static String formatMeter(double meter) {
        String fileSizeString = "m";
        try {

            DecimalFormat df = new DecimalFormat("#.0");
            DecimalFormat dfInt = new DecimalFormat("#");
            if (meter < 1000) {
                fileSizeString = dfInt.format(meter) + "m";
            } else {
                fileSizeString = df.format(meter / 1000.0) + "km";
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        return fileSizeString;
    }

    /**
     * 格式化距离
     *
     * @param meter
     * @return
     */
    public static String formatMeter(int meter) {
        String fileSizeString = "m";
        try {

            DecimalFormat df = new DecimalFormat("#.0");
            if (meter < 1000) {
                fileSizeString = meter + "m";
            } else {
                fileSizeString = df.format(meter / 1000.0) + "km";
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        return fileSizeString;
    }
}
